package com.jack006.admin.controller;

import com.jack006.admin.service.FriendLinkService;
import com.jack006.api.BaseController;
import com.jack006.api.controller.admin.FriendLinkControllerApi;
import com.jack006.grace.result.GraceJSONResult;
import com.jack006.pojo.bo.SaveFriendLinkBO;
import com.jack006.pojo.mo.FriendLinkMO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;

/**
 * @Classname FriendLinkController
 * @Description 友情链接
 * @Date 2021-06-10 08:15
 * @Created by jack
 */
@RestController
public class FriendLinkController extends BaseController implements FriendLinkControllerApi {

    final static Logger logger = LoggerFactory.getLogger(FriendLinkController.class);


    @Autowired
    private FriendLinkService friendLinkService;

    @Override
    public GraceJSONResult saveOrUpdateFriendLink(@Valid SaveFriendLinkBO saveFriendLinkBO,
                                                  HttpServletRequest request,
                                                  HttpServletResponse response) {

        // adminLoginBO ---> **MO
        FriendLinkMO friendLinkMO = new FriendLinkMO();
        BeanUtils.copyProperties(saveFriendLinkBO,friendLinkMO);
        friendLinkMO.setCreateTime(new Date());
        friendLinkMO.setUpdateTime(new Date());

        friendLinkService.saveOrUpdateFriendLink(friendLinkMO);

        return GraceJSONResult.ok();
    }

    @Override
    public GraceJSONResult getFriendLinkList() {
        List<FriendLinkMO> friendLinkMOList =  friendLinkService.queryAllFriendList();
        return GraceJSONResult.ok(friendLinkMOList);
    }

    @Override
    public GraceJSONResult delete(String linkId) {
        friendLinkService.delete(linkId);
        return GraceJSONResult.ok();
    }

    @Override
    public GraceJSONResult queryPortalAllFriendLinkList() {
        List<FriendLinkMO> friendLinkMOList = friendLinkService.queryPortalAllFriendList();
        return GraceJSONResult.ok(friendLinkMOList);
    }
}
